From: Eh2406 Date: Wed, 7 Mar 2018 22:10:55 +0000 (-0500) Subject: use `into_boxed_str` to shrink before we leek X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~2^2~55^2~1 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=827fdf84c8a85cdb02f4446739073a8bbf0e518d;p=cargo.git use `into_boxed_str` to shrink before we leek --- diff --git a/src/cargo/core/interning.rs b/src/cargo/core/interning.rs index 16f9c1347..f8d028b34 100644 --- a/src/cargo/core/interning.rs +++ b/src/cargo/core/interning.rs @@ -4,11 +4,13 @@ use std::collections::HashSet; use std::slice; use std::str; use std::mem; +use std::cmp::Ordering; pub fn leek(s: String) -> &'static str { - let ptr = s.as_ptr(); - let len = s.len(); - mem::forget(s); + let boxed = s.into_boxed_str(); + let ptr = boxed.as_ptr(); + let len = boxed.len(); + mem::forget(boxed); unsafe { let slice = slice::from_raw_parts(ptr, len); str::from_utf8_unchecked(slice) @@ -49,3 +51,18 @@ impl fmt::Debug for InternedString { write!(f, "InternedString {{ {} }}", self.to_inner()) } } + +impl Ord for InternedString { + fn cmp(&self, other: &InternedString) -> Ordering { + self.to_inner().cmp(&other.to_inner()) + } +} + +impl PartialOrd for InternedString { + fn partial_cmp(&self, other: &InternedString) -> Option { + Some(self.cmp(other)) + } +} + +unsafe impl Send for InternedString {} +unsafe impl Sync for InternedString {} \ No newline at end of file